const { contextBridge, ipcRenderer } = require('electron')

const sendUrl = async (url) => {
  let res = await ipcRenderer.invoke('on-url-event', url)
  return res
}

const alert = (msg) => {
  ipcRenderer.invoke('on-alert-event', msg)
}

const open = (url) => {
  ipcRenderer.invoke('on-open-event', url)
}

const getFileList = async () => {
  const fileList = await ipcRenderer.invoke('on-file-event')
  return fileList
}

const openDialog = () => {
  ipcRenderer.send('on-openDialog-event')
}

const renderer = (cb) => {
  ipcRenderer.on('on-renderer-event', () => {
    cb()
  })
}
// 把方法暴露给渲染进程
contextBridge.exposeInMainWorld('myApi', {
  sendUrl,
  alert,
  open,
  getFileList,
  openDialog,
  renderer
})
